<template>
    <el-table :data="tableDialogList" stripe >  
        <el-table-column prop="param" label="参数"  align="center"></el-table-column>
        <el-table-column prop="paraM_Name" label="参数名" align="center"></el-table-column>
        <el-table-column prop="value" label="取值" align="center">
            <template slot-scope="scope">
            <el-input placeholder="请输入参数值" v-model="scope.row.value" clearable :disabled="scope.row.u_EDIT == 0"
            size="small" @change="handleSetListValue(scope.row)" @clear="handleDelList(scope.row.id)"></el-input>
            </template>
        </el-table-column>
        <el-table-column prop="unit" label="单位" align="center"></el-table-column>
    </el-table>
</template>
<script>
import {indexParamList,indexParamSet,indexParamDel} from '@/api/https'
export default ({
    props:{
        indeX_ID:{
            type:Number,
            default:0
        },
        showControl:{
            type:Boolean,
            default:false
        }
    },
    data() {
        return {
            tableDialogList:[]
        }  
    },
    mounted(){
        this.onGetControlList()
    },
    beforeDestroy(){
        this.tableDialogList = []
    },
    methods:{
        onGetControlList(){
            indexParamList({
                INDEX_ID:this.indeX_ID
            }).then(res=>{
                if(res.isSuccess && res.data && res.data.length > 0 ){
                    this.tableDialogList = res.data
                }else{
                    this.tableDialogList = []
                }
            })
        },
        handleSetListValue(data){
            indexParamSet({
                id:data.id,
                indeX_ID:data.indeX_ID,
                param:data.param,
                paraM_Name:data.paraM_Name,
                value:Number(data.value),
            unit:data.unit
            }).then(res=>{
                if(res.isSuccess){
                    this.onGetControlList()
                }else{
                this.$message.error(res.errorMessage)
                }
            })
        },
        handleDelList(id){
            indexParamDel({ID:id}).then(res=>{
                if(res.isSuccess){
                    this.onGetControlList()
                }else{
                    this.onGetControlList()
                    this.$message.error(res.errorMessage)
                }
            })   
        },
    }
})
</script>
<style scoped>
</style>
